package org.lhh.server.common.utils;

import org.pentaho.di.repository.UserInfo;

import javax.servlet.http.HttpServletRequest;

public class SessionUtils {

    private static final String TOKEN = "auth_token";

    public static UserInfo getUserInfo(HttpServletRequest request) {
        String token = request.getHeader(TOKEN);
        EhcacheUtil ehcacheUtil = SpringBeanUtil.getBean(EhcacheUtil.class);
        return ehcacheUtil.getUser(token);
    }

    public static String getUsername() {
        HttpServletRequest httpServletRequest = HttpContextUtils.getHttpServletRequest();
        String token = httpServletRequest.getHeader(TOKEN);
        EhcacheUtil ehcacheUtil = SpringBeanUtil.getBean(EhcacheUtil.class);
        UserInfo user = ehcacheUtil.getUser(token);
        if (user == null)
            return "-";
        return user.getUsername();
    }
}
